package com.hzlj.position.locate.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.fz.common.base.converter.RemoveWrapperPlus;
import com.fz.common.base.core.date.DateUtils;
import com.fz.common.base.dto.DeleteCommonDTO;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.hzlj.position.locate.common.dto.abnProhibitAreas.AbnProhibitAreasQueryParamDTO;
import com.hzlj.position.locate.common.dto.abnProhibitAreas.AbnProhibitAreasQueryResultDTO;
import com.hzlj.position.locate.common.dto.abnProhibitAreas.AbnProhibitAreasWithJzryDTO;
import com.hzlj.position.locate.common.model.AbnProhibitAreas;
import com.hzlj.position.locate.common.model.AbnProhibitAreasJzry;
import com.hzlj.position.locate.mapper.AbnProhibitAreasMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 禁止区域(AbnProhibitAreas)表操作类
 *
 * @author lifh
 * @date 2023-03-28 10:20:33
 */
@Repository
public class AbnProhibitAreasDao extends ServiceImpl<AbnProhibitAreasMapper, AbnProhibitAreas> {
    @Resource
    private AbnProhibitAreasMapper abnProhibitAreasMapper;


    /**
     * 修改数据
     *
     * @param dto 实例对象
     * @return 实例对象
     */
    public boolean updateAbnProhibitAreas(AbnProhibitAreas dto) {
        LambdaQueryWrapper<AbnProhibitAreas> queryWrapper = new QueryWrapper<AbnProhibitAreas>().lambda()
                .eq(AbnProhibitAreas::getId, dto.getId());
        return this.update(dto, queryWrapper);
    }

    /**
     * 删除数据
     *
     * @param dto 实例对象
     * @return 是否成功
     */
    public boolean deleteAbnProhibitAreas(DeleteCommonDTO<String> dto) {
        return RemoveWrapperPlus.remove(this, dto);
    }


    public List<AbnProhibitAreasWithJzryDTO> listAbnProhibitAreasWithJzry() {
        return QueryWrapperConverterPlus.of(abnProhibitAreasMapper)
                .innerJoin(AbnProhibitAreasJzry.class, on -> on.eq(AbnProhibitAreasJzry::getProhibitId, AbnProhibitAreas::getId))
                .list(AbnProhibitAreasWithJzryDTO.class, null, q -> {
                    q.le(AbnProhibitAreas::getStartTime, DateUtils.now())
                            .ge(AbnProhibitAreas::getEndTime, DateUtils.now());
                });
    }

    /**
     * 查询列表：分页
     *
     * @param dto  查询条件
     * @param page 分页信息
     * @return 对象列表
     */
    public QueryPageResultDTO<AbnProhibitAreasQueryResultDTO> pageAbnProhibitAreas(AbnProhibitAreasQueryParamDTO dto, PageParamDTO page) {
        return QueryWrapperConverterPlus.of(abnProhibitAreasMapper)
                .page(AbnProhibitAreasQueryResultDTO.class, dto, page);
    }

}

